package com.dawnling.androidutils.ui;

import android.animation.ObjectAnimator;
import android.content.Intent;
import android.text.Editable;
import android.text.InputFilter;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.dawnling.androidutils.R;
import com.dawnling.androidutils.bean.TestBean;
import com.dawnling.androidutils.ijkplayer.IjkPlayerActivity;
import com.dawnling.androidutils.typeface.AppManager;
import com.dawnling.androidutils.ui.matisse.MatisseActivity;
import com.dawnling.androidutils.ui.scanner.Scanner1Activity;
import com.dawnling.androidutils.ui.scanner.ScannerActivity;
import com.dawnling.androidutils.utils.EditInputFilter;
import com.dawnling.androidutils.utils.PasswordTextWatcher;
import com.dawnling.androidutilslib.BaseActivity;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

/**
 * 首页
 */
public class MainActivity extends BaseActivity {

    private ImageView img;
    private EditText etTest;
    private RelativeLayout rlImg;
    private ObjectAnimator objectAnimator;

    @Override
    protected int initLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        AppManager.getAppManager().addActivity(this);
        img = findViewById(R.id.img);
        rlImg = findViewById(R.id.rlImg);
        etTest = findViewById(R.id.etTest);
        //过滤输入框
        EditInputFilter inputFilter = new EditInputFilter();
        inputFilter.setMax(999);
        InputFilter[] filters = {inputFilter};
        etTest.setFilters(filters);

        EditText etPws = findViewById(R.id.etPws);
        etPws.addTextChangedListener(new PasswordTextWatcher(etPws) {
            @Override
            public void afterTextChanged(Editable s) {
                super.afterTextChanged(s);
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                super.beforeTextChanged(s, start, count, after);
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                super.onTextChanged(s, start, before, count);
            }
        });
    }

    @Override
    protected void initData() {
    }
    public void btn(View v){
        objectAnimator = ObjectAnimator.ofFloat(rlImg,"rotation",90f);
        objectAnimator.start();
    }

    public void btn2(View v) {
        launch(MyRecycleviewActivity.class);
    }

    public void btn3(View v) {
        launch(PhotoActivity.class);
    }

    public void btn4(View v) {
        launch(MyTakePhotoActivity.class);
    }

    public void btn5(View v) {
        launch(ShotActivity.class);
    }

    public void btn6(View v) {
        launch(ToolsTestActivity.class);
    }

    public void btn7(View v) {
        launch(InputActivity.class);
    }

    public void btn8(View v) {
        launch(UtilesActivity.class);
    }

    public void btn9(View v) {
        launch(TypefaceActivity.class);
    }
    public void btn10(View v) {
        IntentIntegrator integrator = new IntentIntegrator(this);
        // 设置要扫描的条码类型，ONE_D_CODE_TYPES：一维码，QR_CODE_TYPES-二维码， 所有类型：ALL_CODE_TYPES
        integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
        integrator.setOrientationLocked(false);
        integrator.setCaptureActivity(ScannerActivity.class);
        integrator.setPrompt(""); //底部的提示文字，设为""可以置空
        integrator.setCameraId(0); //前置或者后置摄像头
        integrator.setBeepEnabled(true);//扫描成功的「哔哔」声，默认开启
        integrator.setBarcodeImageEnabled(false);
        integrator.initiateScan();
    }
    public void btn12(View v) {
        IntentIntegrator integrator = new IntentIntegrator(this);
        // 设置要扫描的条码类型，ONE_D_CODE_TYPES：一维码，QR_CODE_TYPES-二维码， 所有类型：ALL_CODE_TYPES
        integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
        integrator.setOrientationLocked(false);
        integrator.setCaptureActivity(Scanner1Activity.class);
        integrator.setPrompt(""); //底部的提示文字，设为""可以置空
        integrator.setCameraId(0); //前置或者后置摄像头
        integrator.setBeepEnabled(true);//扫描成功的「哔哔」声，默认开启
        integrator.setBarcodeImageEnabled(false);
        integrator.initiateScan();
    }

    public void btn11(View v) {
        launch(NotificationActivity.class);
    }

    public void btn13(View v) {
        launch(IjkPlayerActivity.class);
    }

    public void btn14(View v) {
        launch(MatisseActivity.class);
    }

    public void btn15(View v) {
        launch(WebviewActivity.class);
    }

    public void btn16(View v) {
        launch(ChooseAreaActivity.class);
    }

    public void btn17(View v) {
        Intent intent = new Intent(this, ConstraintLayoutActivity.class);
        startActivity(intent);
    }
    public void btn18(View v) {
        launch(JsonAboutActivity.class);
    }

    public void btn19(View v) {
        launch(DrawLinesActivity.class);
    }

    public void btn20(View v) {
        Intent intent = new Intent(this, DrawLinesActivity.class);
        intent.putExtra("isPoint", true);
        startActivity(intent);
    }

    public void btn21(View v) {
        Intent intent = new Intent(this, KTAreaViewActivity.class);
        startActivity(intent);
    }

    public void btn22(View v) throws CloneNotSupportedException {
        String str = "{\"conferenceStatus\":1,\"conferenceNumber\":\"\",\"openCamera\":false,\"openAudio\":true,\"sdkappID\":1400462571,\"userSig\":\"eJyrVgrxCdZLrSjILEpVsjI0NTU1MjAw0AGLlqUWKVkpGekZKEH4xSnZiQUFmSlAdSYGBiZmRqbmhhCZzJTUvJLMtEywBkMjmPrMdCA3KM8gLyIkODIsxdUp0STZ2SvTID3LOLiwKjI5wN0vP1vf3DcqxSPDONIj1BaqsSQzF*QYMwNLS0MjE0OLWgBcbi9-\"}";
        String str1 = "{\"conferenceStatus\":0,\"conferenceNumber\":\"27950612\",\"sdkappID\":1400462571,\"userSig\":\"eJyrVgrxCdZLrSjILEpVsjI0NTU1MjAw0AGLlqUWKVkpGekZKEH4xSnZiQUFmSlAdSYGBiZmRqbmhhCZzJTUvJLMtEywBkMjmPrMdCA3KM8gLyIkODIsxdUp0STZ2SvTID3LOLiwKjI5wN0vP1vf3DcqxSPDONIj1BaqsSQzF*QYMwNLS0MjE0OLWgBcbi9-\"}";
        TestBean testBean = GsonUtils.fromJson(str, TestBean.class);
        TestBean testBean1 = GsonUtils.fromJson(str1, TestBean.class);
        LogUtils.e("克隆前testBean：" + testBean.toString());
        LogUtils.e("克隆前testBean1：" + testBean1.toString());
        testBean1 = testBean.clone();
        LogUtils.e("克隆后：" + testBean1.toString());
    }
    public final int CUSTOMIZED_REQUEST_CODE = 0x0000ffff;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode != CUSTOMIZED_REQUEST_CODE && requestCode != IntentIntegrator.REQUEST_CODE) {
            super.onActivityResult(requestCode, resultCode, data);
            return;
        }
        if (requestCode == IntentIntegrator.REQUEST_CODE && resultCode == ScannerActivity.RESULT_CODE_PICK_IMAGE) {
            String result = data.getStringExtra("result");
            LogUtils.e("MainActivity相册识别：" + result);
            ToastUtils.showShort("相册识别：" + result);
            return;
        }
        switch (requestCode) {
            case CUSTOMIZED_REQUEST_CODE: {
                Toast.makeText(this, "REQUEST_CODE = " + requestCode, Toast.LENGTH_LONG).show();
                break;
            }
            default:
                break;
        }
        IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data);
        if (result.getContents() == null) {
            LogUtils.e("取消了");
        } else {
            LogUtils.e("相机识别：" + result.getContents());
            ToastUtils.showShort("扫描结果：" + result.getContents());
        }
    }

    public void launch(Class<?> cls) {
        Intent intent = new Intent(this, cls);
        startActivity(intent);
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        ToastUtils.cancel();
    }
}
